﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Environment;

namespace Pixysoft.Weblications.Sango.Battle
{
    class BattleTactical
    {
        long _tacticalTypecode;

        protected BattleTactical(long _tacticalTypecode)
        {
            this._tacticalTypecode = _tacticalTypecode;
        }

        public bool accept(long tacticalTypecode, BattleTeam team)
        {
            if (tacticalTypecode != _tacticalTypecode)
                return false;

            foreach (Entities.Sys_Tacticalpos pos in SysTacticalHelper.searchPositions(_tacticalTypecode))
            {
                //如果当前位置开放等级未到（主城等级小于开放等级），则跳过
                if (team.getTeamLevel() < pos.Openlevel)
                    continue;

                //如果当前位置没有武将，则跳过
                Battler battler = team.tryGetBattler(pos.Positionindex);

                if (battler == null)
                    return false;

                //如果当前位置职业不匹配，则跳过
                foreach (string typecodestring in pos.Professionaltypecode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (int.Parse(typecodestring) == SysProfessionalHelper.searchByCode(battler.getProfessionalSerialCode()).Professionaltypecode)
                        continue;

                    return false;
                }

            }

            return true;
        }
    }
}
